package com.haoxi.gateway.sgip12msg;

public class SGIPCommon {
    public SGIPCommon () {
    }

    public static int ByteToInt ( byte mybyte ) {
        return mybyte;
    }

    public static byte IntToByte ( int i ) {
        return ( byte ) i;
    }

    public static int BytesToInt ( byte mybytes[] ) {
        return ( ( 0xff & mybytes[ 0 ] ) << 8 ) + mybytes[ 1 ];
    }

    public static byte[] IntToBytes ( int i ) {
        byte mybytes[] = new byte[2];
        mybytes[ 1 ] = ( byte ) ( 0xff & i );
        mybytes[ 0 ] = ( byte ) ( ( 0xff00 & i ) >> 8 );
        return mybytes;
    }

    public static byte[] IntToBytes4 ( int i ) {
        /*byte mybytes[] = new byte[4];
        mybytes[3] = (byte) (0xff & i);
        mybytes[2] = (byte) ( (0xff00 & i) >> 8);
        mybytes[1] = (byte) ( (0xff0000 & i) >> 16);
        mybytes[0] = (byte) ( (0xff000000 & i) >> 24);
        return mybytes;*/
        byte abyte0[] = new byte[4];
        abyte0[ 3 ] = ( byte ) i;
        i >>>= 8;
        abyte0[ 2 ] = ( byte ) i;
        i >>>= 8;
        abyte0[ 1 ] = ( byte ) i;
        i >>>= 8;
        abyte0[ 0 ] = ( byte ) i;
        return abyte0;
    }

    public static byte[] IntToBytes3 ( int i ) {
        byte mybytes[] = new byte[3];
        mybytes[ 2 ] = ( byte ) ( 0xff & i );
        mybytes[ 1 ] = ( byte ) ( ( 0xff00 & i ) >> 8 );
        mybytes[ 0 ] = ( byte ) ( ( 0xff0000 & i ) >> 16 );
        return mybytes;
    }

    public static void IntToBytes4 ( int i, byte mybytes[] ) {
        mybytes[ 3 ] = ( byte ) ( 0xff & i );
        mybytes[ 2 ] = ( byte ) ( ( 0xff00 & i ) >> 8 );
        mybytes[ 1 ] = ( byte ) ( ( 0xff0000 & i ) >> 16 );
        mybytes[ 0 ] = ( byte ) ( int ) ( ( ( long ) 0xff000000 & ( long ) i ) >> 24 );
    }

    public static long BytesToLong ( byte mybytes[] ) {
        return ( ( long ) 255 & ( long ) mybytes[ 0 ] ) << 24 | ( ( long ) 255 & ( long ) mybytes[ 1 ] ) << 16 |
               ( ( long ) 255 & ( long ) mybytes[ 2 ] ) << 8 | ( long ) mybytes[ 3 ];
    }

    public static int Bytes4ToInt ( byte mybytes[] ) {
        return ( 0xff & mybytes[ 0 ] ) << 24 | ( 0xff & mybytes[ 1 ] ) << 16 | ( 0xff & mybytes[ 2 ] ) << 8 | 0xff & mybytes[ 3 ];
    }

    public static byte[] LongToBytes ( long l ) {
        byte mybytes[] = new byte[4];
        mybytes[ 3 ] = ( byte ) ( int ) ( ( long ) 255 & l );
        mybytes[ 2 ] = ( byte ) ( int ) ( ( ( long ) 65280 & l ) >> 8 );
        mybytes[ 1 ] = ( byte ) ( int ) ( ( ( long ) 0xff0000 & l ) >> 16 );
        mybytes[ 0 ] = ( byte ) ( int ) ( ( ( long ) 0xff000000 & l ) >> 24 );
        return mybytes;
    }

    public static int getRandomInt () {
        Double doub = new Double ( Math.random () * ( double ) - 1 );
        return doub.intValue ();
    }

    public static void BytesCopy ( byte source[], byte dest[], int sourcebegin, int sourceend, int destbegin ) {
        int j = 0;
        for ( int i = sourcebegin; i <= sourceend; i++ ) {
            dest[ destbegin + j ] = source[ i ];
            j++;
        }
    }

    public static String getTimeStamp () {
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat ( "MMddHHmmss" );
        return format.format ( java.util.Calendar.getInstance ().getTime () );
    }

    public static final int MAX_QUE_LENGTH = 100;
    public static final int MAX_MSG_CONTENT_LENGTH = 140;
    public static final int MSG_HEAD_LENGTH = 20;
    public static final int MSG_BIND_BODY_LENGTH = 41;
    public static final int MSG_BIND_REP_BODY_LENGTH = 9;
    public static final int MSG_SUBMIT_REP_BODY_LENGTH = 9;
    public static final int MSG_STATUS_REPORT_LENGTH = 44;
    public static final int MSG_DELIVER_REP_BODY_LENGTH = 9;
    public static final int MSG_REPORT_BODY_LENGTH = 9;
    public static final byte RESERVED = 0;
    public static final int SUBMIT_OK = 0;
    public static final int SUBMIT_ERROR_STRUCTURE = 1;
    public static final int SUBMIT_ERROR_COMMANDTYPE = 2;
    public static final int SUBMIT_ERROR_SEQ_DUPLICATE = 3;
    public static final int SUBMIT_ERROR_MSG_LENGTH = 4;
    public static final int SUBMIT_ERROR_FEECODE = 5;
    public static final int SUBMIT_ERROR_CONTENT_LENGTH_EXCEED = 6;
    public static final int SUBMIT_ERROR_SERVERID = 7;
    public static final int SUBMIT_ERROR_FLOW_CONTROL = 8;
    public static final int SUBMIT_ERROR_OTHERS = 9;
    public static final byte SUBMIT_DATA = 1;
    public static final byte END_SMS = 2;
    public static final byte SMSGW_RESP = 3;
    public static final int MSG_TYPE_ASCII = 0;
    public static final int MSG_TYPE_WRITECARD = 3;
    public static final int MSG_TYPE_BINARY = 4;
    public static final int MSG_TYPE_EMS = 5;
    public static final int MSG_TYPE_UCS2 = 8;
    public static final int MSG_TYPE_CHINESE = 15;
    public static final int SGIP_BIND=  0x1;
    public static final int SGIP_BIND_RESP = 0x80000001;
    public static final int SGIP_UNBIND= 0x2;
    public static final int SGIP_UNBIND_RESP= 0x80000002;
    public static final int SGIP_SUBMIT= 0x3;
    public static final int SGIP_SUBMIT_RESP=0x80000003;
    public static final int SGIP_DELIVER=0x4;
    public static final int SGIP_DELIVER_RESP=0x80000004;
    public static final int SGIP_REPORT= 0x5;
    public static final int SGIP_REPORT_RESP=0x80000005;
    public static final int SGIP_ACTIVE_TEST=0x10000001;
    public static final int SGIP_ACTIVE_TEST_RESP=0x10000010;
 
    

}